package vn.co.thn.android.videohot.activity;

import java.util.ArrayList;

import vn.co.thn.android.serviceconnect.callback.RequestCallBack;
import vn.co.thn.android.serviceconnect.request.Param;
import vn.co.thn.android.serviceconnect.request.RequestService;
import vn.co.thn.android.serviceconnect.request.ServiceTask;
import vn.co.thn.android.videohot.R;
import vn.co.thn.android.videohot.VHApp;
import vn.co.thn.android.videohot.VHUrlApi;
import vn.co.thn.android.videohot.data.VHDeviceItemData;
import vn.co.thn.android.videohot.json.VHJsonCategoryList;
import android.content.Intent;
import android.os.Bundle;

public class VHSplashActivity extends VHCommonActivity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.vh_splash_activity);
		ServiceTask serviceTask = new ServiceTask();
		if (VHApp.getPreference().getDeviceID() == null) {
			mRequestService.setUrl(VHUrlApi.Api_Device_add);
			ArrayList<Param> Params = new ArrayList<Param>();
			Params.add(new Param("DeviceId", VHApp.getDeviceID()));
			mRequestService.setParams(Params);
			mRequestService.setRequestCallBack(new RequestCallBack<VHDeviceItemData>() {

				@Override
				public void onResult(VHDeviceItemData data, boolean isUpdate) {
					// TODO Auto-generated method stub
					VHApp.getPreference().setDeviceID(data.getDeviceId());
				}

				@Override
				public void onResult(ArrayList<VHDeviceItemData> data, boolean isUpdate) {
					// TODO Auto-generated method stub

				}

			});
			
			serviceTask.add(mRequestService, 1);
		}
		RequestService RequestCategory=new RequestService(VHApp.getInstance());
		RequestCategory.setUrl(VHUrlApi.Api_Category_List);
		RequestCategory.setRequestCallBack(new RequestCallBack<VHJsonCategoryList>() {

			@Override
			public void onResult(VHJsonCategoryList data, boolean isUpdate) {
				// TODO Auto-generated method stub
				VHApp.getPreference().setCategoryList(data);
			}

			@Override
			public void onResult(ArrayList<VHJsonCategoryList> data, boolean isUpdate) {
				// TODO Auto-generated method stub

			}
		});
		serviceTask.add(RequestCategory, 2);
		serviceTask.setRequestProcessCallBack(this);
		serviceTask.start();
	}

	@Override
	public void HideProcess() {
		// TODO Auto-generated method stub
		super.HideProcess();
		startActivity(new Intent(this, VHMainActivity.class));
		finish();
	}
}
